function test() {
    for(var i = 0;i<100000;i++){
        $.ajax({
            url:'/sc/admin/list_student',
            success:function (data) {
                console.log(i);
            }

        })
    }
}
function sendReq(target){
    if(confirm("确定修改?")){
        var msg={};
        var currentTr = $(this).closest('tr');
        if(currentTr.size()<=0) {
            currentTr = $(target.closest('tr'));
        }
        console.log(target);
        console.log(currentTr);
        var sid = currentTr.find('.table_in_input').eq(0).val();
        var sname = currentTr.find('.table_in_input').eq(1).val();
        var to_school_time = currentTr.find('.table_in_input').eq(2).val();
        var max_num = currentTr.find('.table_in_input').eq(3).val();
        var sex = currentTr.find('.scb option:selected').val();
        var birthday = currentTr.find('.table_in_input').eq(4).val();
        var stel = currentTr.find('.table_in_input').eq(5).val();
        var major_id = currentTr.find('option:selected').attr('major_id');

        msg.sid=sid;
        msg.sname=sname;
        msg.to_school_time=to_school_time;
        msg.max_num=max_num;
        msg.sex=sex;
        msg.birthday=birthday;
        msg.stel=stel;
        msg.major_id=major_id;
        console.log(msg);
        console.log(JSON.stringify(msg));
        $.ajax({
            url : "/sc/admin/alter_student",
            type : 'get',
            data:msg,
            contentType: "application/json; charset=utf-8",
            dataType : "text",
            success : function(data) {

                if(data=='success'){
                    alert('修改成功!');
                }
                else {
                    //window.location.reload();
                    alert('修改失败!');
                }
            }
        });
    }
    else{
        window.location.reload();
    }
}
(function() {
    function resetPsw(target) {
        $.ajax({
            url:'/sc/admin/reset_student_psw',
            data:'sid='+target.attr('sid'),
            success:function (data) {
                if(data=='success'){
                    alert('修改成功!');
                }
                else {
                    //window.location.reload();
                    alert('修改失败!');
                }
            }
        })
    }
    var queryCourse = function() {
        $.ajax({
            url : "/sc/admin/list_course?condition="+$('#input').val(),
            type : 'get',
            /*dataType : "text",*/
            success : function(data) {
                console.log(data);
                //console.log(data);
                /* console.log(data);
                 updateTable(data);
                 bindAction();*/
            }
        });
    };

    bindAction();
    $("#input").bind('change', queryCourse);
    $("#btn").bind('click', queryCourse);
    $('.table_in_input').mousedown(function (event) {
        event = event ? event : window.event;
        var target = event.target ? event.target : event.srcElement;
        $(target).attr('readonly','true');
    });

    function bindAction() {
        //修改学生
        $('.table_in_input').dblclick(function (event) {

            $(this).attr('readonly',false);
        });
        $('.mcb').change(sendReq);
        $('.tcb').change(sendReq);
        $('.scb').change(sendReq);
        $('.table_in_input').change(sendReq);
        $('.rest_psw').click(function () {
            resetPsw($(this));
        });
    }

    function updateTable(data) {
        $('.symbol').remove();
        eval("var o=" + data + "");
        for (var i = 0; i < o.length; i++) {
            var tempNode = $("<tr class='symbol' row=''></tr>");
            $(tempNode).attr('row',i);
            for (var j = 0; j < o[i].length; j++) {
                tempNode.append("<td>" + "<input class='table_in_input' readonly='true' type='text' value='" +o[i][j]+
                    "'>" + "</td>")
            }
            tempNode.append("<td><input type='checkbox' class='check_cid'/></td>");
            $(".course_table").append(tempNode);
        }
    }


    //删除学生
    $('#btn_delete').click(function () {


        function checkedArr() {
            var a = new Array();
            var o = $('.sid:checked');
            o.each(function () {
                a.push($(this).attr('sid'));
            })
            return a;
        }

        console.log('sid='+checkedArr());
        $.ajax({
            url : "/sc/admin/delete_student",
            type : 'post',
            data:'sid='+checkedArr(),
            dataType : "text",
            success : function(data) {

                if(data=='success'){

                    alert('删除成功!');
                }else {
                    alert('删除失败!');
                }
            }
        });

    });

    function editableTable() {
        var inputNode = $('<input type="text" class="table_in_input"/>');
        $('.course_table td')	.click(appendInput);
        function appendInput(event){
            event = event ? event : window.event;
            var target = event.target ? event.target : event.srcElement;
            var content = $(target).html();
            $(inputNode).attr('value',content);
            $(target).html("");
            $(target).append(inputNode);
            $(target).unbind('click',appendInput);
        }
        $('.course_table td  :input[text]').change(function (event) {
            console.log(event);
            event = event ? event : window.event;
            var target = event.target ? event.target : event.srcElement;
            var content = $(target).attr('value');
            console.log(content);
            $(target).remove();
            $(target).parent().val(content);
        });
    }
})();